#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>

int Index = 0; //窗口索引，判断当前应该打开哪个窗口

void gotoxy( int x, int y){
    COORD coord;
    coord.X = x;
    coord.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

void clrscr() {
    system("cls");
}

int ReadMaxScore(){
	return 666;
}

int ReadScore(){
    return 99;
}

void CreateEndWindow(){
        //如果刷新记录，更新最高分
        if (ReadScore() > ReadMaxScore()){
            //更新最高分
        }
        //屏幕初始化
		//清屏
		clrscr();
		//获取屏幕缓冲区信息
		HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    	CONSOLE_SCREEN_BUFFER_INFO csbi;
   		GetConsoleScreenBufferInfo(hConsole, &csbi);
   		//获取控制台宽度、高度
  	  	int consoleWidth = csbi.srWindow.Right - csbi.srWindow.Left + 1;
  	  	int consoleHeight = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
        //绘制边框，大小为控制台长、宽的2/5，偏移量为3/10
        int padding_width = consoleWidth*3/10;
        int padding_height = consoleHeight*3/10;
        //绘制窗口边界
        int i;
        //up
        gotoxy(padding_width,padding_height);
        for (i=padding_width;i<consoleWidth-padding_width;i++){
            putchar('*');
        }
        //down
        gotoxy(padding_width,consoleHeight-padding_height);
        for (i=padding_width;i<=consoleWidth-padding_width;i++){
            putchar('*');
        }
        //left
        for (i=padding_height;i<consoleHeight-padding_height;i++){
            gotoxy(padding_width,i);
            putchar('*');
        }
        //right
        for (i=padding_height;i<consoleHeight-padding_height;i++){
            gotoxy(consoleWidth-padding_width,i);
            putchar('*');
        }
        //绘制左上角信息
        //最高分
        gotoxy(0,0);
        printf ("历史最高分：%d\n",ReadMaxScore() );
        //F5刷新
        printf ("按下F5刷新");
        //绘制窗口内容
        //游戏结束
        gotoxy(consoleWidth/2-4,consoleHeight*2/5);
        printf ("游 戏 结 束");
        //本次得分
        gotoxy(consoleWidth/2-4,consoleHeight/2);
        printf ("本次得分：%d",ReadScore() );
        //菜单栏选项
        gotoxy(consoleWidth/2-4,consoleHeight*3/5);
        printf ("重新开始(\"1\")");
        gotoxy(consoleWidth/2-4,consoleHeight*3/5+2);
        printf ("返回主菜单(\"Esc\")");
        //接收菜单栏输入
        int tmp;
        while (1){
            //重新开始
            tmp = getch();
            if (tmp == '1'){ 
                Index = 1;
                break;
            }
            //Esc
            if (tmp == 0x1b){
                Index = 0;
                break;
            }
            //F5
           if ( tmp == 0x0 ){
			tmp=getch();
			if ( tmp == 0x3f ){
				clrscr();
				CreateEndWindow();
				break;
			}
		}
     }
}

int main(){
    CreateEndWindow();
    return 0;
}